package com.bk.game.mc;

import android.content.Intent;
import android.net.Uri;

import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Disposable;
import com.bk.game.TwitterActivity;
import com.bk.game.WebActivity;
import com.bk.game.global.BkGlobal;
import com.bk.game.screen.HelpScreen;
import com.bk.game.screen.RankScreen;

/**
 * 描述:主页的按钮
 * 
 * @author linqiang(866116)
 * @Since 2012-9-7
 */
public class TopBtn extends Actor implements Disposable {

	private String name;

	private Sprite sprite;
	private float scaleX, scaleY;

	private float x, y;

	public TopBtn(String name, TextureRegion region, float left, float top, float width, float heigh) {
		this.name = name;
		sprite = new Sprite(region);
		scaleX = width * BkGlobal.factorx;
		scaleY = heigh * BkGlobal.factory;
		sprite.setSize(scaleX, scaleY);
		this.x = left * BkGlobal.factorx;
		this.y = top * BkGlobal.factory;
		sprite.setColor(0, 0, 0, 0);
		sprite.setPosition(this.x, this.y);
	}

	@Override
	public void dispose() {

	}

	@Override
	public void draw(SpriteBatch spriteBatch, float arg1) {
		sprite.draw(spriteBatch);
	}

	@Override
	public Actor hit(float arg0, float arg1) {
		if (arg0 > x && arg1 > y && arg0 < x + sprite.getWidth() && arg1 < y + sprite.getHeight()) {
			return this;
		}
		return null;
	}

	@Override
	public boolean touchDown(float x, float y, int pointer) {
		BkGlobal.btnSound.play();
		sprite.setColor(0.2f, 0.2f, 0.2f, 0.8f);
		return true;
	}

	@Override
	public void touchDragged(float x, float y, int pointer) {
		super.touchDragged(x, y, pointer);
	}

	@Override
	public boolean touchMoved(float x, float y) {
		return super.touchMoved(x, y);
	}

	@Override
	public void touchUp(float x, float y, int pointer) {
		sprite.setColor(0, 0, 0, 0);
		action();
	}

	/**
	 * 描述:
	 * 
	 * @author linqiang(866116)
	 * @Since 2012-9-7
	 */
	private void action() {
		Screen screen = null;
		if ("btn_top1".equals(name)) {
			screen = new HelpScreen();
		} else if ("btn_top2".equals(name)) {
			screen = new RankScreen();
		} else if ("btn_top3".equals(name)) {
			Intent intent = new Intent(BkGlobal.getInstance(), WebActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			BkGlobal.getInstance().startActivity(intent);
		} else if ("btn_top4".equals(name)) {
			Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=com.yy.game.bullycat&feature=apps_topselling_new_free");
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			BkGlobal.getInstance().startActivity(intent);
		} else if ("btn_end1".equals(name)) {
			screen = BkGlobal.mainScreen;
		} else if ("btn_end2".equals(name)) {
			screen = BkGlobal.gameScreen;
		} else if ("twitter".equals(name)) {
			// screen = new HelpScreen();
			Intent intent = new Intent(BkGlobal.getInstance(), TwitterActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			BkGlobal.getInstance().startActivity(intent);
		}
		if (screen != null)
			BkGlobal.currentGame.setScreen(screen);
	}
}
